<?php
/**
 * 媒体编辑页面
 *
 * @author Alen
 * @since 1.0.0 2013-10-3 sutroon
 */
class Media_EditAction extends AdmincpAction {
    //put your code here
    public function index(){
        
        // 设置页面导航
        $this->set_breadcrumb(array('媒体管理'=>'?m=Media_List','编辑'=>'###'));
        
        // 设置页面标题
        $this->set_h1('');
        
        // 获取主键编号
        $id=request_numeric('id');
        $fid=request_numeric('fid');
        // 读取数据
        
        $biz=new SoBizMedia();
        if($id){
            $data=$biz->read_one($id);
            if(!$data) redirect('媒体不存在','?m=Media_List');
            $fid=$data['ParentID'];
        }else{
            $data=array('Title'=>'','Content'=>'','Picture'=>'');
        }
        
        // 设置页面信息,如页面标题,meta信息等
        $this->set_page_info($data['Title']);
        
        if(!$this->dm) $this->dm=new SoDataModule();
        // 构建表单内容
        $this->uig->begin_form(true);
        $this->uig->add_textfield('标题','title',$data['Title'],'标题长度不超过30个字符');
        $this->uig->add_selectfield('父级','parent',$this->dm->select_arrayset('tgeneraladvertisement','ParentID=0 order by Ordinal' ),$fid);
        $this->uig->add_filefield('图片','img',$data['Picture']);
        $this->uig->add_editorfield('内容','content',$data['Content']);
        $this->uig->add_controlfield();
        $this->uig->add_hiddenfield(array('action'=>'save'));
        $this->uig->end_form();
        $this->assign('form', $this->uig->get_text());    
        // 显示模板
        $this->display();
    }
    public function save(){
        $biz=new SoBizMedia();
        $msg=$biz->save();
        if($msg=='SUCCESS'){            
            redirect('保存成功','?m=Media_List');
        }else{
            redirect($msg);
        }
    }
}

?>
